<?php
            
use app\model\Theme; 



//新抽奖
//活动规则
$yx_lt_rules = [];
$yx_lt_rule_ids = $_P['yx_lt_rule_id'];
$yx_lt_rule_sort = $_P['yx_lt_rule_sort'];
$yx_lt_rule_content = $_P['yx_lt_rule_content'];
//if (is_array($yx_lt_rule_ids)){
//    foreach ($yx_lt_rule_ids as $k =>$v){
//        $dd = ['rule_content'=>$yx_lt_rule_content[$k],'rule_sort'=>$yx_lt_rule_sort[$k]];
//        $yx_lt_rules[] = $dd;
//    }
//}

require_once YX_PLUGIN_CORE . 'inc/plugin_model.php';
require_once get_path('plugin/lottery/core/model.php');
$yx_lt_rules = \LotteryModel::productYxLtRule($_P);
if ($_P['yx_lt_no_sign_up'] && (int)$_P['yx_lt_no_sign_up']>0){
    $_P['yx_lt_lucky_star'] = 1;
}else{
    $_P['yx_lt_lucky_star'] =0;
}
if (!$_P['yx_lt_double_flag'] && intval($_P['yx_lt_chance_limit'])>8){
    $yx_lt_chance_limit= 8;
}else{
    $yx_lt_chance_limit = intval($_P['yx_lt_chance_limit']);
}
if ($_P['yx_lt_open_red_package']){
    if ($_P['red_envelopes_day_amount']<=0){
        return_msg('每日发放红包总金额不合法');
    }
    if ($_P['red_envelopes_total_amount']<=0){
        return_msg('本次活动发放红包总金额不合法');
    }
}
if (!$system['fenxiao']){
    $_P['yx_lt_open_red_package'] = 0;
}
if (!$_P['yx_lt_double_flag'] && $_P['yx_lt_chance_limit']>8){
    return_msg('奖项重复获取关闭，抽奖机会上限最多为8次');
}
//判断更新的弹窗的次数是正数还是负数
//$old_config =   Theme::getConfig($themeid);
$diff_num = intval($_P['yx_lt_show_no_chance_num']) - intval($config_old['yx_lt_show_no_chance_num']);
if ($diff_num>0){
    //给所有抽奖机会大于等于0的增加弹窗次数
    $sql = " update ".tablename(t_fans)." set show_modal_num=show_modal_num+$diff_num where jihui>0 and themeid=$id";
}else{
    //给所有弹窗次数大于0的减少弹窗次数
    $diff_num = abs($diff_num);
    $sql = " update ".tablename(t_fans)." set show_modal_num=show_modal_num - $diff_num where show_modal_num>0 and themeid=$id";
}
db_query($sql);
$yx_lt_mode = 0;
$yx_lt_top_img = 'https://css2020.yixuan.net/2020css/plugin/lottery/images/topBg.jpg';
if (isset($_P['yx_lt_mode']) && $_P['yx_lt_mode']==1){
    //新模式下
    $yx_lt_mode = 1;
    $yx_lt_top_img = 'https://css2020.yixuan.net//2020css/lottery/lottery2022/image/bg_01.jpg';
}
//单页面下的配置检查
//if ($_P['yx_lt_mode']==1 && (!$_P['yx_lt_friend_help'] || $_P['yx_lt_friend_help']<1 || !$_P['yx_lt_friend_help_limit'] || $_P['yx_lt_friend_help_limit']<1)){
if ($_P['yx_lt_mode']==1 && (!$_P['yx_lt_friend_help'] && !$_P['yx_lt_friend_view'])){
    return_msg('活动编辑【九宫格抽奖】抽奖机会中 "好友到访或好友助力" 需二者选一个进行配置');
}

$lt_diy_prize_imgs = $_P['lt_diy_prize_imgs'];
$into_prize_imgs = [];
if ($lt_diy_prize_imgs){
    if (is_array($lt_diy_prize_imgs)){
        foreach ($lt_diy_prize_imgs as $k => $val){
            array_push($into_prize_imgs,tomedia($val));
        }
    }else{
        array_push($into_prize_imgs,tomedia($lt_diy_prize_imgs));
    }
}
$yx_lt_begintime = strtotime($_P['yx_lt_time']['start']);
$yx_lt_endtime = strtotime($_P['yx_lt_time']['end']);
//抽奖时间限制  0 不限制  1时间限制
$is_limit_end_time = intval($_P['is_limit_end_time']);
if ($is_limit_end_time==0){
    $is_limit_end_time = 0;
    $yx_lt_begintime = strtotime($_P['themetime']['start']);
    $yx_lt_endtime = strtotime($_P['themetime']['end']) ;
}
//好友到访跟好友助力  二选一
$yx_lt_friend_view = intval($_P['yx_lt_friend_view']);
$yx_lt_friend_help = intval($_P['yx_lt_friend_help']);
if ($yx_lt_friend_view && $yx_lt_friend_help){
    return_msg('活动编辑【九宫格抽奖】抽奖机会中 "好友到访与好友助力只能选择其中一项"');
}
//调整颜色为统一配置
$yx_lt_home_bg1_c1 = isset($_P['yx_lt_home_bg1_c1'])?$_P['yx_lt_home_bg1_c1']:'#C34730';
$yx_lt_home_bg2_c2 = isset($_P['yx_lt_home_bg2_c2'])?$_P['yx_lt_home_bg2_c2']:'#C34730';

$yx_lt_home_bg3_c1 = isset($_P['yx_lt_home_bg3_c1'])?$_P['yx_lt_home_bg3_c1']:'#FADC80';
$yx_lt_home_bg3_c2 = isset($_P['yx_lt_home_bg3_c2'])?$_P['yx_lt_home_bg3_c2']:'#FADC80';
if (empty($_P['yx_lt_myprize_tips']) && !$_P['yx_lt_convert_only']){
    $_P['yx_lt_myprize_tips'] = '温馨提示：所有已获得奖品只能兑换一个';
}

$tempconfig=array(
    'yx_lt_rules' => $yx_lt_rules,//活动规则
    'yx_lt_show_rules' => intval($_P['yx_lt_show_rules']),//活动规则是否展示 0展示 1不展示
    'yx_lt_show' => intval($_P['yx_lt_show']),//显示位置
    'yx_lt_show_no_chance_num' => intval($_P['yx_lt_show_no_chance_num']),//无抽奖机会弹窗的显示次数
    'yx_lt_show_flag_method' => intval($_P['yx_lt_show_flag_method']),//显示中奖记录和抽奖攻略
    'yx_lt_new_fan_terms' => intval($_P['yx_lt_new_fan_terms']),//新用户判断条件  0不限制 1手机号 2头像
    'yx_lt_has_worker' => intval($_P['yx_lt_has_worker']),//判断员工是否参与
    'yx_lt_main_order' => intval($_P['yx_lt_main_order']),//判断是否下单后好友抢购有效

    'yx_lt_begintime' => $yx_lt_begintime,//抽奖开始时间
    'yx_lt_endtime' => $yx_lt_endtime,//抽奖结束时间
    'is_limit_end_time' => $is_limit_end_time,//抽奖结束时间 限制
    'yx_lt_top_img' => tomedia($_P['yx_lt_top_img']?tomedia($_P['yx_lt_top_img']):$yx_lt_top_img),//首页背景图
//    'yx_lt_btm_tips' => trim($_P['yx_lt_btm_tips']),//奖品底部提示语
    'yx_lt_convert_only' => intval($_P['yx_lt_convert_only']),//奖品唯一性兑换
    'yx_lt_lucky_star' => trim($_P['yx_lt_lucky_star']),//幸运星
    'yx_lt_lucky_btm' => trim($_P['yx_lt_lucky_btm']),//幸运星按钮文字
    'yx_lt_double_flag' => intval($_P['yx_lt_double_flag']),//重复中奖
    'yx_lt_lucky_icon' => trim($_P['yx_lt_lucky_icon']?tomedia($_P['yx_lt_lucky_icon']):'https://css2020.yixuan.net/2020css/plugin/lottery/images/stars.png'),//幸运星图标
    'yx_lt_convert_method' => trim($_P['yx_lt_convert_method']),//兑奖方式
    'yx_lt_convert_tel' => trim($_P['yx_lt_convert_tel']),//兑奖电话
    'yx_send_people' => trim($_P['yx_send_people']),//兑奖电话
    'yx_lt_convert_btn' => trim($_P['yx_lt_convert_btn']),//兑换页核销按钮文字
    'yx_lt_convert_btm_tips' => trim($_P['yx_lt_convert_btm_tips']),//兑换底部提示语
    'yx_lt_convert_back_img' => tomedia($_P['yx_lt_convert_back_img']?tomedia($_P['yx_lt_convert_back_img']):'https://css2020.yixuan.net/2020css/plugin/lottery/images/lessonBg.png'),//首页背景图
    'yx_lt_friend_help_title' => trim($_P['yx_lt_friend_help_title']),//好友助力顶部标题
    'yx_lt_friend_help_top_tips' => trim($_P['yx_lt_friend_help_top_tips']),//好友助力顶部提示语
    'yx_lt_con' => intval($_P['yx_lt_con']),//抽奖条件  0 不显示  1下单后
    'yx_lt_receive_con' => intval($_P['yx_lt_receive_con']),//抽奖手机客资条件
    'yx_lt_dummy' => intval($_P['yx_lt_dummy']),//抽奖手机虚拟人数
    'yx_lt_open_red_package' => intval($_P['yx_lt_open_red_package']),//开启红包奖品
    'red_package_icon' => 'https://css2020.yixuan.net/2020css/plugin/lottery/images/bag.png',//我的奖品中红包图标默认
    'red_package_min_amount' => trim($_P['red_package_min_amount'])?trim($_P['red_package_min_amount']):(int)0.3,//红包提现最低金额
    'red_envelopes_day_amount' => intval($_P['red_envelopes_day_amount']),//日红包金额
    'red_envelopes_total_amount' => intval($_P['red_envelopes_total_amount']),//红包总金额
    'red_package_btm_tips' => trim($_P['red_package_btm_tips']?$_P['red_package_btm_tips']:'我的红包'),//红包金额底部文字
    'yx_lt_myprize_tips' => trim($_P['yx_lt_myprize_tips']?$_P['yx_lt_myprize_tips']:''),//我的奖品底部提示文字
    'red_package_right_btn_txt' => trim($_P['red_package_right_btn_txt']?$_P['red_package_right_btn_txt']:'立即提现'),//红包提现按钮文字
    'yx_lt_chance_limit' => intval($yx_lt_chance_limit),//抽奖机会上限
    'yx_lt_no_sign_up' => intval($_P['yx_lt_no_sign_up']),//未报名可抽
    'yx_lt_self_order' => intval($_P['yx_lt_self_order']),//成功报名加抽
    'yx_lt_friend_order' => intval($_P['yx_lt_friend_order']),//邀请一位好友报名加抽
    'yx_lt_first_share_moment' => intval($_P['yx_lt_first_share_moment']),//分享朋友圈加抽第1天
    'yx_lt_second_share_moment' => intval($_P['yx_lt_second_share_moment']),//分享朋友圈加抽第2天
    'yx_lt_third_share_moment' => intval($_P['yx_lt_third_share_moment']),//分享朋友圈加抽第3天
    'yx_lt_share_moment_user_type' => intval($_P['yx_lt_share_moment_user_type']),//0未报名+已报名 1已报名
    'yx_lt_friend_view' => intval($_P['yx_lt_friend_view']),//几个好友到访增加1次抽奖机会
    'yx_lt_view_user_type' => intval($_P['yx_lt_view_user_type']),//好友到访 前提条件 0未报名+已报名 1已报名
    'yx_lt_friend_view_limit' => isset($_P['yx_lt_friend_view_limit'])?intval($_P['yx_lt_friend_view_limit']):0,//好友到访 限制次数上限
    'yx_lt_timeset' => intval($_P['yx_lt_timeset'])>99?99:intval($_P['yx_lt_timeset']),//定时奖励
    'yx_lt_timeset_limit' => intval($_P['yx_lt_timeset_limit']),//定时奖励最大次数
    'yx_lt_timeset_user_type' => intval($_P['yx_lt_timeset_user_type']),//定时奖励 前提条件 0未报名+已报名 1已报名
    'yx_lt_share_lead_img' => $_P['yx_lt_share_lead_img']?tomedia($_P['yx_lt_share_lead_img']):'https://css2020.yixuan.net/2019css/default/images/fenxiao_lottery.png',
    'yx_lt_mode'=>$yx_lt_mode,
//    单页面下的按钮文字设置
    'yx_lt_home_txt'=>$_P['yx_lt_home_txt']?$_P['yx_lt_home_txt']:'活动首页',
    'yx_lt_home_txt_c1'=>$_P['yx_lt_home_txt_c1']?$_P['yx_lt_home_txt_c1']:'#292929',
    'yx_lt_home_txt_c2'=>$_P['yx_lt_home_txt_c2']?$_P['yx_lt_home_txt_c2']:'#292929',
    'yx_lt_home_txt_c'=>$_P['yx_lt_home_txt_c']?$_P['yx_lt_home_txt_c']:'#F8CD88',

    'yx_lt_invite_txt'=>$_P['yx_lt_invite_txt']?$_P['yx_lt_invite_txt']:'立即邀请',
    'yx_lt_invite_txt_c1'=>$yx_lt_home_bg1_c1?$yx_lt_home_bg1_c1:'#EF4442',
    'yx_lt_invite_txt_c2'=>$yx_lt_home_bg2_c2?$yx_lt_home_bg2_c2:'#EF4442',
    'yx_lt_invite_txt_c'=>$_P['yx_lt_invite_txt_c']?$_P['yx_lt_invite_txt_c']:'#ffffff',

    'yx_lt_powered_txt'=>$_P['yx_lt_powered_txt']?$_P['yx_lt_powered_txt']:'已帮TA助力',
    'yx_lt_powered_txt_c1'=>$yx_lt_home_bg3_c1,
    'yx_lt_powered_txt_c2'=>$yx_lt_home_bg3_c2,
    'yx_lt_powered_txt_c'=>$_P['yx_lt_powered_txt_c']?$_P['yx_lt_powered_txt_c']:'#C34730',

    'yx_lt_power_txt'=>$_P['yx_lt_power_txt']?$_P['yx_lt_power_txt']:'助力TA',
    'yx_lt_power_txt_c1'=>$yx_lt_home_bg3_c1,
    'yx_lt_power_txt_c2'=>$yx_lt_home_bg3_c2,
    'yx_lt_power_txt_c'=>$_P['yx_lt_power_txt_c']?$_P['yx_lt_power_txt_c']:'#C34730',

    'yx_lt_join_txt'=>$_P['yx_lt_join_txt']?$_P['yx_lt_join_txt']:'我也要参与',
    'yx_lt_join_txt_c1'=>$yx_lt_home_bg1_c1,
    'yx_lt_join_txt_c2'=>$yx_lt_home_bg2_c2,
    'yx_lt_join_txt_c'=>$_P['yx_lt_join_txt_c']?$_P['yx_lt_join_txt_c']:'#ffffff',

    'yx_lt_my_txt'=>$_P['yx_lt_my_txt']?$_P['yx_lt_my_txt']:'查看我的抽奖',
    'yx_lt_my_txt_c1'=>$yx_lt_home_bg1_c1,
    'yx_lt_my_txt_c2'=>$yx_lt_home_bg2_c2,
    'yx_lt_my_txt_c'=>$_P['yx_lt_my_txt_c']?$_P['yx_lt_my_txt_c']:'#ffffff',

    'yx_lt_home_bg1_c1'=>$yx_lt_home_bg1_c1,
    'yx_lt_home_bg2_c2'=>$yx_lt_home_bg2_c2,
    'yx_lt_home_bg3_c1'=>$yx_lt_home_bg3_c1,
    'yx_lt_home_bg3_c2'=>$yx_lt_home_bg3_c2,

    'yx_lt_top_info_bg'=>$_P['yx_lt_top_info_bg']?$_P['yx_lt_top_info_bg']:'#e65d3b',

    'yx_lt_ft_size'=>$_P['yx_lt_ft_size']?$_P['yx_lt_ft_size']:'28',
    'yx_lt_ft_bold'=>$_P['yx_lt_ft_bold']?$_P['yx_lt_ft_bold']:'400',

//    'yx_lt_steer_img'=>$_P['yx_lt_steer_img']?tomedia($_P['yx_lt_steer_img']):'https://css2020.yixuan.net//2020css/lottery/lottery2022/image/lt_into_txt.png',//首页进入抽奖的引导图
    'yx_lt_steer_img'=>$_P['yx_lt_steer_img']?tomedia($_P['yx_lt_steer_img']):'http://img2020.yixuansoft.cn/images/2/2022/08/ZZicEED9Tdb92id6ecZnXFecB989Z0.png',//首页进入抽奖的引导图
    'lt_into_txt'=>$_P['lt_into_txt']?$_P['lt_into_txt']:'查看抽奖',//首页进入抽奖页面的按钮文字
    'lt_diy_prize_imgs'=>$into_prize_imgs,//图片组
//    好友助力
    'yx_lt_friend_help' => intval($_P['yx_lt_friend_help']),//几个好友助力增加1次抽奖机会
    'yx_lt_friend_help_limit' => intval($_P['yx_lt_friend_help_limit']),//好友助力机会上限
    'yx_lt_help_user_type' => intval($_P['yx_lt_help_user_type']),//好友助力好友条件 0 不限制 1已报名
    'yx_lt_help_target' => intval($_P['yx_lt_help_target']),//好友助力客资 0不收集 1手机号 2表单收集
    'yx_lt_diy_tc' => intval($_P['yx_lt_diy_tc']),//好友助力客资 0不收集 1手机号 2表单收集
);
$config =array_merge($config,$tempconfig);


